package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Objects;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.cucc.service.attr.handler.DiscountNumAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;

/**
 * @ClassName : DiscountNumAttrLinkHandler
 * @Description : 计算折扣率=最终订购费/[套包价格*灵活共享系数*(1+平台功能费%)]；
 * @Author : wei.yanhong
 * @Date : 2020/11/19 17:23
 */
@Service
@AttrHandler(DiscountNumAttrHandler.class)
public class DiscountNumAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Resource
    private OperateInstAttrService operateInstAttrService;

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteAttr area = inst.getAttr("2_0000222");
        if (Objects.isNull(area)) {
            return;
        }
        // 地市改动则清空区县、装机地址
        operateInstAttrService.setAttrValue(inst, "2_0000222", "", data.getSceneInstId(), null);
        operateInstAttrService.setAttrValue(inst, "2_0000211", "", data.getSceneInstId(), null);
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }

    public static void main(String[] args) {
        int a = 1099;
        int b = 93;
        DecimalFormat df = new DecimalFormat("0.00"); //格式化小数
        String num = df.format((float) a / b); //返回的是String类型
        System.out.println("ddd===" + num);
        a = 1099;
        b = 93;
//        double f1 = new BigDecimal((float) b / a).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//        System.out.println("ddd===" + f1);

    }

}
